﻿using Pay.Core;
using Pay.Data;
using Pay.DTO;
using Pay.IService;
using Pay.Service;
using Pay.TO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace Pay.Token.Controllers {
    [AppAuthorize("Member")]
    public class MerchantController : GeneralController {
        private IMerchIntroduceService _merchIntroduceService;
        private ISettingService _settingService;
        private ISoupTaskService _iSoupTaskService;
        public MerchantController( IMerchIntroduceService merchIntroduceService,ISettingService settingService, ISoupTaskService soupTaskService) {
           
            _merchIntroduceService = merchIntroduceService;
            _settingService = settingService;
            _iSoupTaskService = soupTaskService;

    }
        #region 商户列表
        [AllowAnonymous]
        public ActionResult MerchantList() {
            return View();
        }
        [AllowAnonymous]
        public PartialViewResult _MerchantList(PageQuery query) {
            var list = _merchIntroduceService.GetAppMerchIntroducePageList(query);
          ViewBag.img_url = RequestMethod.token_imgurl;
            return PartialView(list);
        }
        #endregion
        #region 商户详情
        public ActionResult Merchant(long Id) {
            ViewData["site_img"] = RequestMethod.token_imgurl;
            var result = _iSoupTaskService.GetSoupTaskByType(TO.ETaskType.MerchIntroduce);
            
            var model = _merchIntroduceService.AppGetMerchIntroduce(Id, UserId);
            ViewData["soup_value"] = model.soup_value;
            ViewData["merchant"] = model;
          return  View();
        }
        [HttpPost]
        public async Task<JsonResult> GetPower(long Id) {
            var result= await _iSoupTaskService.TaskRecive(UserId, ETaskType.MerchIntroduce, Id);
            if (result) {
                return Json(ResultToJson.Json("领取成功", true), JsonRequestBehavior.AllowGet);
            } else {
                return Json(ResultToJson.Json("您还没有达到任务要求，无法完成任务", false), JsonRequestBehavior.AllowGet);
            }

        }
        #endregion

    }
}
